<?php

namespace App\Kuafu\Feishu\Model;

use App\Kuafu\Base\Model\BaseModel;
use Illuminate\Database\Eloquent\Relations\HasMany;

class FsDepartmentsModel extends BaseModel
{
    protected $table = "fs_departments";

    protected $fillable = [
        "departmentId",
        "openDepartmentId",
        "leaderUserId",
        "chat_id",
        "memberCount",
        "name",
        "parentDepartmentId",
        "order",
        "isDeleted",
        "createdAt",
        "updatedAt"
    ];

    /**
     * @return HasMany
     */
    public function userRel(): HasMany
    {
        return $this->hasMany(FsUserModel::class, "departmentId", "openDepartmentId")
                    ->where("rmsUserId", ">", 0)
                    ->select([
                        "id",
                        "userId",
                        "rmsUserId",
                        "name",
                        "nickname",
                        "departmentId"
                    ]);
    }
}
